﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SmallERP.MODEL.PrintManage;
using SmallERP.DAL;
using SmallERP.COM;
using Smallerp.Contracts;
using System.Data;

namespace SmallERP.Bll.PrintManage
{
     

    public class BoardDetail
    {
        IOperateDB _OperateDb;
        public BoardDetail(IOperateDB inop)
        {
            _OperateDb = inop;
        }
        public List<BoardDetailInfo> GetBoardDetailInfo(int boardId)
        {
            List<BoardDetailInfo> list = new List<BoardDetailInfo>();
            //using (smallerpDataContext entities = new smallerpDataContext())
            //{
            //    Board bd = entities.Board.FirstOrDefault(b => b.BoardId == boardId);
            //    if (!bd.PicMakeUp.IsLoaded)
            //    {
            //        bd.PicMakeUp.Load();
            //    }
            //    foreach (var item in bd.PicMakeUp)
            //    {
            //        if (!item.photoInfoReference.IsLoaded)
            //        {
            //            item.photoInfoReference.Load();
            //        }
            //        photoInfo photo = item.photoInfo;
            //        BoardDetailInfo boardDetailInfo = new BoardDetailInfo();
            //        boardDetailInfo.Height = photo.Height;
            //        boardDetailInfo.PhotoId = photo.PhotoId;
            //        boardDetailInfo.PhotoName = photo.PhotoName;
            //        boardDetailInfo.PicPath = photo.PicPath;
            //        if (!photo.orderInfoReference.IsLoaded)
            //        {
            //            photo.orderInfoReference.Load();
            //        }
            //        boardDetailInfo.ProductName = photo.orderInfo.OrderName;
            //        boardDetailInfo.Status = photo.Status;
            //        boardDetailInfo.Width = photo.Width;
                    
            //        list.Add(boardDetailInfo);
            //    }
            //}
            string QueryBoard = "select photoinfo.Height,photoinfo.PhotoId,photoinfo.PhotoName,photoinfo.PicPath,orderInfo.OrderName as ProductName,photoinfo.status,photoinfo.Width from board,orderinfo,photoinfo,picmakeup where board.boardid=picmakeup.boardid and orderinfo.orderproductid=photoinfo.orderproductid and photoinfo.photoid=picmakeup.photoid and "

                +" board.boardid="+boardId;
            DataTable table=_OperateDb.QueryDataTable(QueryBoard);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                BoardDetailInfo boardDetailInfo = new BoardDetailInfo() { 
                    Height=Convert.ToInt32(table.Rows[i]["Height"]),
                    PhotoId = Convert.ToInt32(table.Rows[i]["PhotoId"]),
                    PhotoName = Convert.ToString(table.Rows[i]["PhotoName"]),
                    PicPath = Convert.ToString(table.Rows[i]["PicPath"]),
                    ProductName = Convert.ToString(table.Rows[i]["ProductName"]),
                    Status = Convert.ToInt32(table.Rows[i]["Status"]),
                    Width = Convert.ToInt32(table.Rows[i]["Width"]),
                };
                list.Add(boardDetailInfo);
 
            }
                return list;

        }
    }
}
